package com.zhongli.devplatform.mapper.sys;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface ReadRoleResourceMapper {

    @Insert("insert into read_role_resource values(#{roleId},#{resourceId})")
    void insert(@Param("roleId") Integer roleId, @Param("resourceId") Integer resourceId);

    @Delete("delete from read_role_resource where role_id = #{roleId}")
    void deleteByRole(Integer roleId);

    @Delete("delete from read_role_resource where resource_id = #{resourceId}")
    void deleteByResource(Integer resourceId);

    @Select("select resource_id from read_role_resource where role_id = #{roleId}")
    List<Long> listResourceIdByRole(Integer roleId);

    @Select("select code from read_role where id in (select role_id from read_role_resource where resource_id = #{resourceId})")
    List<String> listRoleCodeByResource(Integer resourceId);


}
